package org.Shiikong_Memory.SakuraBlockFrame;

import lombok.Getter;
import org.Shiikong_Memory.SakuraBlockFrame.BasisTool.ConfigTool;
import org.Shiikong_Memory.SakuraBlockFrame.BasisTool.LanguageModules;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;

public abstract class SakuraBlockPlugiun extends JavaPlugin {
    @Getter
    private JavaPlugin plugin;
    @Getter
    private Logger logger;
    @Getter
    private ConfigTool configTool;
    @Getter
    public LanguageModules languageModules;

    @Override
    public void onEnable() {
        plugin = this;
        logger = this.getLogger();
        try {
            logger.info(String.format("%s插件正在启动中...", this.getPluginName()));
            configTool = new ConfigTool(this);
            languageModules = LanguageModules.createLanguageModules(configTool);
            configLoad();
            if (this.isOpenPapi()){
                if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
                    papiLoad();
                }else{
                    logger.warning("未检测到PlaceholderAPI插件前置，已自动关闭papi变量功能");
                }
            }
            registerFunction();
            logger.info(String.format("%s插件正在启动成功", this.getPluginName()));
        }catch (Exception e){
            logger.warning(String.format("%s插件正在启动失败", this.getPluginName()));
            e.printStackTrace();
        }
    }

    /**
     * 设置插件名称
     * @return 插件名称
     */
    public String getPluginName() {
        return this.getPluginName();
    }

    /**
     * 是否打开papi变量功能，如果需要打开需要重写方法
     * @return 是否打开papi变量功能
     */
    public boolean isOpenPapi(){
        return false;
    }

    /**
     * 配置加载
     */
    public abstract void configLoad();

    /**
     * Papi变量注册加载
     */
    public abstract void papiLoad();

    /**
     * 注册加载
     */
    public abstract void registerFunction();

    /**
     * 重载插件功能
     */
    public void reload(){
        configTool = new ConfigTool(this);
        languageModules = LanguageModules.createLanguageModules(configTool);
        this.reloadConfig();
    }
}